IF EXISTS(SELECT * FROM sys.objects o WHERE o.[object_id]= OBJECT_ID('Usp_ShoppingCartAdd') AND o.[type]=N'P')
BEGIN
	DROP PROC Usp_ShoppingCartAdd
END
GO
CREATE PROCEDURE  Usp_ShoppingCartAdd(
	@MemLoginID NVARCHAR(50),
	@ProductGuid UNIQUEIDENTIFIER,
	@Attributes NVARCHAR(250),
	@ExtensionAttriutes NVARCHAR(250),
	@BuyNumber INT,
	@BuyPrice DECIMAL(18,2),
	@IsJoinActivity int,
	@IsPresent INT
)	
AS 

	IF EXISTS(SELECT * FROM ShopNum1_Cart WHERE MemLoginID=@MemLoginID AND ProductGuid=@ProductGuid)
		BEGIN
			UPDATE ShopNum1_Cart
				SET BuyNumber =BuyNumber+@BuyNumber
			WHERE 
				MemLoginID=@MemLoginID AND ProductGuid=@ProductGuid
		END
	ELSE
		BEGIN
			INSERT INTO ShopNum1_Cart
			(	Guid,MemLoginID,ProductGuid,OriginalImge,Name,RepertoryNumber,BuyNumber,
				MarketPrice,ShopPrice,BuyPrice,Attributes,IsShipment,IsReal,ExtensionAttriutes,
				ParentGuid,IsJoinActivity,CartType,IsPresent,CreateTime,DetailedSpecifications,
				UsedScore,ArrivedWithMoney,AgentID
			)
			SELECT	NEWID(),@MemLoginID,@ProductGuid,OriginalImge,NAME,RepertoryNumber,@BuyNumber,
					MarketPrice,ShopPrice,@BuyPrice,@Attributes,0,IsReal,@ExtensionAttriutes,
					NULL,@IsJoinActivity,0,@IsPresent,GETDATE(),[Description],0,0,null
			FROM ShopNum1_Product 
			WHERE Guid=@ProductGuid
		END
	